package org.rambadger.deployer.utils;

/**
 * Created with IntelliJ IDEA.
 * User: chtompki
 * Date: 10/30/13
 * Time: 9:03 PM
 * To change this template use File | Settings | File Templates.
 */
public class MutableInt {

    private int value;
    private boolean valueSet;

    public MutableInt(int v) {
        value = v;
        valueSet = true;
    }

    public MutableInt() {
        value = 0;
        valueSet = false;
    }

    public boolean isSet() {
        return valueSet;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
        this.valueSet = true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + value;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (obj instanceof Integer) {
            return (((Integer)obj).equals(value));
        } else if (obj instanceof Long) {
            return (((Long)obj).equals(value));
        } else if (getClass() != obj.getClass()) {
            return false;
        }
        MutableInt other = (MutableInt) obj;
        if (value != other.value) {
            return false;
        }
        return true;
    }
}
